package com.ruoyi.web.sso.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.web.sso.domain.Area;
import com.ruoyi.web.sso.domain.DTO.AreaDTO;
import com.ruoyi.web.sso.domain.DTO.AreaDetailDTO;
import com.ruoyi.web.sso.domain.DTO.AreaListDTO;
import com.ruoyi.web.sso.domain.vo.AreaVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 园所信息Mapper接口
 * 
 * @author ruoyi
 * @date 2021-11-03
 */
public interface AreaMapper 
{

    Area areaIdGetArea(String id);
    /**
     * 查询园所信息
     * 
     * @param id 园所信息主键
     * @return 园所信息
     */
    public AreaVO selectAreaById(String id);

    /**
     * 查询园所信息
     *
     * @param id 园所信息主键
     * @return 园所信息
     */
    public List<AreaVO> selectAreaByIds(String[] id);

    /**
     * 查询园所信息列表
     * 
     * @param area 园所信息
     * @return 园所信息集合
     */
    public List<AreaVO> selectAreaList(Area area);

    /**
     * 新增园所信息
     * 
     * @param area 园所信息
     * @return 结果
     */
    public int insertArea(Area area);

    /**
     * 修改园所信息
     * 
     * @param area 园所信息
     * @return 结果
     */
    public int updateArea(Area area);

    /**
     * 删除园所信息
     * 
     * @param id 园所信息主键
     * @return 结果
     */
    public int deleteAreaById(String id);

    /**
     * 批量删除园所信息
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAreaByIds(String[] ids);

    /**
     * 用户ID查询所属园区
     * @param staffId
     * @return
     */
    List<Area> getStaffIdByArea(String staffId);


    AreaDetailDTO getAreaDetailDTO(String staffId);


    AreaDTO getAreaDTO(String staffId);

    List<AreaListDTO> getInChargeArea(@Param("staffId") String staffId);


    List<AreaVO> staffIdByAreaList(@Param("staffId") String staffId, @Param("areaName") String areaName);


    List<Map<String,Object>>  areaByRoleList(@Param("id")String id,@Param("roleName")String roleName);


    List<AreaDTO> getStaffGroupByAreaList(String id);

    @Select("select a.id,a.group_id as groupId,area_name as areaName,admin_staff as adminStaff  from area a  inner join  staff s on s.area_id = a.id  where s.id =#{staffId}  ")
    Area getArea(@Param("staffId")String staffId);



    @Select("select a.id,a.area_name as name ,a.deleted status,a.latitude,a.longtitude  from  " +
            "((select * from area  where latitude >= #{latitude} and  longtitude >= #{longtitude} order by latitude asc LIMIT #{num} ) " +
            "union " +
            "(select * from area  where latitude < #{latitude} and  longtitude < #{longtitude} order by latitude desc LIMIT #{num} )) a LIMIT #{num} ")
    List<AreaDTO> areasByLocation(@Param("longtitude")float longtitude,@Param("latitude")float latitude,@Param("num")Integer num);


    @Select("select  a.id,a.area_name as name ,a.deleted status,a.latitude,a.longtitude  from area  a where 1=1 " +
            "  and if( #{pcaCode} !='', a.pca_code  LIKE  CONCAT( #{pcaCode} , '%'),1=1)   " +
            "  and  a.pca_code_desc LIKE  CONCAT( '%', #{pcaName}, '%') ")
    List<AreaDTO>  areasByLocationLike(@Param("pcaCode")String pcaCode,@Param("pcaName")String pcaName);

    List<Area> getGroupAll(String id);

    @Select("select a.id,a.area_name as name ,a.deleted status,a.latitude,a.longtitude  from  area a ")
    List<AreaDTO> getAllArea();


    @Select("select a.id,a.area_name as name ,a.deleted status,a.latitude,a.longtitude  from  area a  where  a.area_name = #{areaName}")
    List<AreaDTO> getAreaName(@Param("areaName")String areaName);
}